import 'package:city_pickers/city_pickers.dart';
import 'package:city_pickers/modal/result.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:get/get.dart';

import '../pay/showLockInfoDialog.dart';
import '../widgets/dialog/ContentCancelConfirm.dart';
import '../widgets/dialog/MyBottomDialog.dart';
class utilDialog {

  static  showDialog() {
    Get.defaultDialog(
      title: "提示",
      middleText: "确定要删除吗？",
      textConfirm: "确定",
      textCancel: "取消",
      confirmTextColor: Colors.white,
      onConfirm: () {
        print("点击了确认");
        Get.back(); // 关闭对话框
      },
      onCancel: () {
        print("点击了取消");
      },
    );
  }


  static snackbarBOTTOM(){//tost 底部顶部弹出
    Get.snackbar(
      "提示", "操作成功",
      snackPosition: SnackPosition.BOTTOM, // 显示位置
      backgroundColor: Colors.black87,
      colorText: Colors.white,
      duration: Duration(seconds: 2),
    );
  }

  static snackbarTOP(String msg){//tost 底部顶部弹出
    Get.snackbar(
      "提示", msg,
      snackPosition: SnackPosition.TOP, // 显示位置
      backgroundColor: Colors.black87,
      colorText: Colors.white,
      duration: Duration(seconds: 2),
    );
  }
  static panel(){//底部面板
    Get.bottomSheet(
      Container(
        color: Colors.white,
        height: 200,
        child: Column(
          children: [
            ListTile(
              leading: Icon(Icons.music_note),
              title: Text("音乐"),
              onTap: () => Get.back(),
            ),
            ListTile(
              leading: Icon(Icons.video_call),
              title: Text("视频"),
              onTap: () => Get.back(),
            ),
            ListTile(
              leading: Icon(Icons.video_call),
              title: Text("取消"),
              onTap: () => Get.back(),
            ),
          ],
        ),
      ),
      backgroundColor: Colors.white,
      isDismissible: true,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
      ),
    );

  }

  static showCancelConfirmDialog({
    required BuildContext context,
    String title = "提示", // 默认值
    required String message, // 必填
    VoidCallback? onCancel,  // 可选
    VoidCallback? onConfirm, // 可选
  }){
    MyBottomDialog.show(
      context: context,
      width: 300, // 👈 固定宽高
      height: 200,            // 👈 高度可自定义或用 double.infinity
      borderRadius: 20,       // 👈 可设置为 0 取消圆角
      animationType: DialogAnimationType.popup,//底部划出
      builder: (ctx) =>  ContentCancelConfirm(title: title, message:message,
          // onConfirm: (){
          //   Navigator.pop(context);
          // }
          onCancel: onCancel,
          onConfirm: onConfirm,
          ),
    );
  }
   //时间选择器
  static void showTimeRangePicker(BuildContext context ,int _startHour,int _endHour,final Function(int startTime,int endTime)? onConfirm) {
    int tempStart = _startHour;//默认开始时间
    int tempEnd = _endHour;//默认结束时间

    showCupertinoModalPopup(
      context: context,
      builder: (_) => Container(
        height: 300,
        color: Colors.white,
        child: Column(
          children: [
            // 顶部按钮
            Container(
              color: Colors.grey[200],
              padding: EdgeInsets.symmetric(horizontal: 16),
              height: 60,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  CupertinoButton(
                    child: Text("取消"),
                    onPressed: () => Navigator.pop(context),
                  ),
                  CupertinoButton(
                    child: Text("确认"),
                    onPressed: () {
                        _startHour = tempStart;
                        _endHour = tempEnd;
                        if (onConfirm != null) {
                          onConfirm(_startHour, _endHour);
                        }

                      Navigator.pop(context);
                    },
                  ),
                ],
              ),
            ),
            // 滚轮部分
            Expanded(
              child: Row(
                children: [
                  // 开始时间
                  Expanded(
                    child: CupertinoPicker(
                      scrollController: FixedExtentScrollController(initialItem: tempStart),
                      itemExtent: 40,
                      onSelectedItemChanged: (index) {
                        tempStart = index;
                      },
                      children: List.generate(24, (i) => Center(child: Text('$i 时'))),
                    ),
                  ),
                  // 结束时间
                  Expanded(
                    child: CupertinoPicker(
                      scrollController: FixedExtentScrollController(initialItem: tempEnd),
                      itemExtent: 40,
                      onSelectedItemChanged: (index) {
                        tempEnd = index;
                      },
                      children: List.generate(24, (i) => Center(child: Text('$i 时'))),
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  static Future<void>  showpPovinceCityArea(BuildContext context, final Function(String? provinceName,String? cityName,String? areaName)? onConfirm) async{

      Result? result = await CityPickers.showCityPicker(
        context: context,
        showType: ShowType.pca, // 省市区三级联动（默认）
        // 可以设置默认值，比如：
        // provinceCode: '110000',
        // cityCode: '110100',
        // areaCode: '110101',
      );
      if (result != null&&onConfirm != null) {
        print('>]城市：${result.provinceName} ${result.cityName} ${result.areaName}');
        onConfirm(result.provinceName,result.cityName,result.areaName);
      }

}
  static Future<void>  showpPovince(BuildContext context, final Function(String? provinceName)? onConfirm) async{

    Result? result = await CityPickers.showCityPicker(
      context: context,
      showType: ShowType.p, // 省市区三级联动（默认）
      // 可以设置默认值，比如：
      // provinceCode: '110000',
      // cityCode: '110100',
      // areaCode: '110101',
    );
    if (result != null&&onConfirm != null) {
      print('>]城市：${result.provinceName}"); //${result.cityName} ${result.areaName}');
      onConfirm(result.provinceName);
    }

  }

  static void payDialog(BuildContext context){
    showLockInfoDialog(context);
  }



}